package com.programmercarl.greed;

/**
 * https://leetcode.cn/problems/wiggle-subsequence/description/
 * 摆动序列
 *
 * @author yulongtian
 * @create 2025-02-06 13:38
 */
public class Test02 {
    public static void main(String[] args) {
        Test02 test02 = new Test02();
        System.out.println(test02.wiggleMaxLength(new int[]{1, 17, 5, 10, 13, 15, 10, 5, 16, 8}));
        // [16, -12, 5, 3, 2, -5, -5, 11, -8]
    }

    public int wiggleMaxLength(int[] nums) {
        if (nums.length == 1) {
            return 1;
        }
        if (nums.length == 2) {
            if (nums[0] != nums[1]) {
                return 2;
            }
        }
        int sum = 1;
        Boolean flag = null;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == nums[i - 1]) {
                continue;
            }
            if (nums[i] > nums[i - 1]) {
                if (flag != null && flag) {
                    continue;
                }
                flag = true;
            } else {
                if (flag != null && !flag) {
                    continue;
                }
                flag = false;
            }
            sum++;
        }
        return sum;
    }
}
